/*
 * DatatypePropertyPanel.java
 *
 * Created on 13. Juni 2008, 13:21
 */

package twi.query.template2.view;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

/**
 *
 * @author  Soeren
 */
public class DatatypePropertyPanel extends javax.swing.JPanel {

    /** Creates new form DatatypePropertyPanel 
     * @param pcl 
     * @param propertyName 
     * @param edit */
    public DatatypePropertyPanel(boolean edit, final String propertyName, final PropertyChangeListener pcl) {
        initComponents();
        this.jCheckBox1.setText(propertyName);
        this.jCheckBox1.addItemListener(new ItemListener(){
			@Override
			public void itemStateChanged(ItemEvent e) {
				pcl.changeProperty(jCheckBox1.isSelected(), propertyName);
			}
        });
        this.jCheckBox1.setEnabled(edit);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jCheckBox1 = new javax.swing.JCheckBox();
        jTextField1 = new javax.swing.JTextField();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(twi_project.TWI_ProjectApp.class).getContext().getResourceMap(DatatypePropertyPanel.class);
        jCheckBox1.setText(resourceMap.getString("jCheckBox1.text")); // NOI18N
        jCheckBox1.setName("jCheckBox1"); // NOI18N

        jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
        jTextField1.setName("jTextField1"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jCheckBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jCheckBox1)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
	public boolean isProperty(String prop) {
		return this.jCheckBox1.getText().equals(prop);
	}

	public String getValue() {
		return this.jTextField1.getText();
	}

}
